/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Lop;

import conn.JavaConnectDb;
import java.sql.Connection;
import java.util.Date;
import javax.swing.JOptionPane;
import oracle.jdbc.OraclePreparedStatement;
import oracle.jdbc.OracleResultSet;
/**
 *
 * @author nhung
 */
public class lCQQL {
    private String macq;
    private String tencq;
    
    
    OraclePreparedStatement pst;
    OracleResultSet rs;
    public lCQQL()
    {  
    }

    public lCQQL(String macq, String tencq)
    {
        this.macq = macq;
        this.tencq = tencq;
    }
    
    public String getmacq() {
        return macq;
    }
    public void setmacq(String macq) {
        this.macq = macq;
    }
    public String gettencq() {
        return tencq;
    }
    public void settencq(String tencq) {
        this.tencq = tencq;
    }
public OracleResultSet selectcqql(OConnection cnn){
        try{
            String sql = "select * from CQQL";
            pst=(OraclePreparedStatement) cnn.createConnection().prepareStatement(sql);
            rs = (OracleResultSet) pst.executeQuery();
         }catch(Exception e){
            JOptionPane.showMessageDialog(null, e);
        }
        return rs;
    } 


public void insertcqql(OConnection cnn)
{
        try{
            String sql = "insert into CQQL values(T_CQQL(?,?))";
            pst=(OraclePreparedStatement) cnn.createConnection().prepareStatement(sql);
            pst.setString(1, this.macq);
            pst.setString(2, this.tencq);
            pst.executeQuery();
            JOptionPane.showMessageDialog(null, "Them thanh Cong");
         }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Kiem tra lai CSDL hoac trung Ma Loai");
        }
}
public void updatecqql(OConnection cnn)
    {
        try{
            String sql = "update CQQL set tencq=? where macq=?";
            pst=(OraclePreparedStatement) cnn.createConnection().prepareStatement(sql);
            pst.setString(2, macq);
            pst.setString(1, tencq);
            pst.executeQuery();
            JOptionPane.showMessageDialog(null, "Cap nhat thanh cong");        
         }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Cap nhat khong thanh cong");
        } 
    }

public void deletecqql(OConnection cnn)
    {
        try{
            String sql = "delete from CQQL where macq=?";
           pst=(OraclePreparedStatement) cnn.createConnection().prepareStatement(sql);
            pst.setString(1, macq);
            pst.executeQuery();
            JOptionPane.showMessageDialog(null, "Xoa thanh cong");        
         }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Xoa khong thanh cong");
        } 
    }
}
